<?php
declare(strict_types=1);
/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/10
 * Time: 11:25
 */

namespace App\Controller\Admin;

use App\Controller\AppBaseController;
use App\Model\Admin;
use App\Model\Group;
use App\Model\Party;
use App\Model\User;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\AdminApiAuth;


#[Controller(prefix: 'admin')]
#[Middleware(AdminApiAuth::class)]
class AdminController extends AppBaseController
{

    /**
     * 后台--获取用户信息
     * @return object
     */
    #[RequestMapping(path:'info',methods: 'get')]
    public function info(): object
    {
        try{
            //验证管理员信息
            $checkInfo = $this->checkAdmin();
            if($checkInfo['status']==40002) return $this->reMsg->re(10002,$checkInfo['message']);
            $_admin = $checkInfo['data'];

            $adminInfo = Admin::getAdminInfoByUserIdBrief($_admin->id);
            return $this->reMsg->re(1,'success',$adminInfo);
        }catch (\Exception $exception){
            return $this->diyError->errorJson($exception);
        }
    }



    /**
     * 后台--推送标签列表
     * @return object
     */
    #[RequestMapping(path: 'pushTipList',methods: 'get')]
    public function pushTipList(): object
    {

        try{
            //验证管理员信息
            $this->checkAdmin();
            //支部列表
            $partyList = Party::where('status',1)->selectRaw('id,name')->get();
            $backData = [
                'party_list'=>$partyList,
                'user_type_list'=>[
                    ['id'=>'1','name'=>'群众'],
                    ['id'=>'2','name'=>'党员'],
                    ['id'=>'7','name'=>'通讯员'],
                    ['id'=>'8','name'=>'支部委员'],
                    ['id'=>'9','name'=>'支部书记'],
                    ['id'=>'10','name'=>'党委委员']
                ] //推送标签
            ];
            return $this->reMsg->re(1,'success',$backData);
        }catch (\Exception $exception){
            return $this->diyError->errorJson($exception);
        }
    }


    /**
     * 推送标签列表
     * @return object
     */
//    #[RequestMapping(path:'pushTipList1',methods: 'get')]
//    public function pushTipList1(): object
//    {
//        try{
//            //验证管理员信息
//            $this->checkAdmin();
//
//            $position_cate_one_arr = User::whereNotNull('position_cate_one')->pluck('position_cate_one')->toArray();
//            $position_cate_one = array_unique($position_cate_one_arr);
//            $position_cate_two_arr = User::whereNotNull('position_cate_two')->pluck('position_cate_two')->toArray();
//            $position_cate_two = array_unique($position_cate_two_arr);
//            $politics_face_arr = User::whereNotNull('politics_face')->pluck('politics_face')->toArray();
//            $politics_face = array_unique($politics_face_arr);
//            $party_cadre_arr = User::whereNotNull('party_cadre')->pluck('party_cadre')->toArray();
//            $party_cadre = array_unique($party_cadre_arr);
//            $list = [
//                'position_cate_one' => array_merge($position_cate_one),
//                'position_cate_two' => array_merge($position_cate_two),
//                'politics_face' =>array_merge($politics_face),
//                'party_cadre'=>array_merge($party_cadre),
//            ];
//            $next = 2;
//            return $this->reMsg->re(1,'success',['list' => $list, 'next' => $next]);
//        }catch (\Exception $exception){
//            return $this->diyError->errorJson($exception);
//        }
//    }


    /**
     * 标签列表--后台
     * @return object
     */
    #[RequestMapping(path:'groupList',methods: 'get')]
    public function groupList(): object
    {
        try{
            //验证管理员信息
            $this->checkAdmin();

            $where['status'] = 1;
            $list = Group::where($where)->get();
            $next = 2;
            return $this->reMsg->re(1,'success',['list' => $list, 'next' => $next]);
        }catch (\Exception $exception){
            return $this->diyError->errorJson($exception);
        }
    }





}